import { ecs } from "db://oops-framework/libs/ecs/ECS";
import { Role } from "../../role/Role";
import { Equip } from "../Equip";

/** 穿戴装备 */
@ecs.register('EquipWear')
export class EquipWearComp extends ecs.Comp {
    role: Role = null!;

    reset() {
        this.role = null!;
    }
}

export class EquipWearSystem extends ecs.ComblockSystem implements ecs.IEntityEnterSystem {
    filter(): ecs.IMatcher {
        return ecs.allOf(EquipWearComp);
    }

    entityEnter(e: Equip): void {
        var comp = e.get(EquipWearComp);
        e.EquipModel.role = comp.role;
        comp.role.RoleModelEquip.equips.set(e.EquipModel.type, e);

        e.remove(EquipWearComp);
    }
}